<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\IndexService;
use App\Service\H5\TongjiService;
use Illuminate\Http\Request;

class TongjiController extends BaseController
{
    //个人
    public function person(Request $request)
    {
        $pas['urole_id'] = $request->post('urole_id', 0);
        $pas['udepart_id'] = $request->post('udepart_id', 0);
        $pas['ustaff_id'] = $request->post('ustaff_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['staff_id'] = $request->post('uid', 0);
        $pas['year'] = $request->post('year_id', date('Y', time()));
        $pas['month'] = $request->post('month_id', date('m', time()));
        $pas['sort_id'] = $request->post('sort_id', 0);
        $res = TongjiService::person($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //项目
    public function item(Request $request)
    {
        $pas['urole_id'] = $request->post('urole_id', 0);
        $pas['udepart_id'] = $request->post('udepart_id', 0);
        $pas['uid'] = $request->post('uid', 0);
        $pas['is_leader'] = $request->post('is_leader', 0);
        $pas['year'] = $request->post('year_id', date('Y', time()));
        $pas['month'] = $request->post('month_id', date('m', time()));
        // $pas['sort_id'] = $request->post('sort_id', 0);
        $res = TongjiService::item($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    //所有
    public function all(Request $request)
    {
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['staff_id'] = $request->post('staff_id', 0);
        $pas['year'] = $request->post('year', date('Y', time()));
        $pas['month'] = $request->post('month_id', 0);
        $pas['sort_id'] = $request->post('sort_id', 0);
        $res = TongjiService::all($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }

    //环比
    public function huan(Request $request)
    {
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['staff_id'] = $request->post('staff_id', 0);
        $pas['year'] = $request->post('year', date('Y', time()));
        $pas['month'] = $request->post('month_id', 0);
        $pas['sort_id'] = $request->post('sort_id', 0);
        $res = TongjiService::huan($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data'], $res['total']);
    }
}